//
//  BuZhouViewController.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/8/13.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "BuZhouViewController.h"
#import "BuZhouViewCell.h"
@interface BuZhouViewController ()

@end

@implementation BuZhouViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"诉求步骤";
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 140;
    [self.tableView registerNib:[UINib nibWithNibName:@"BuZhouViewCell" bundle:nil] forCellReuseIdentifier:@"BuZhouViewCell"];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    // self.tableView.style == UITableViewStyleGrouped;
    
     //  UITableViewStylePlain,          // regular table view
     //  UITableViewStyleGrouped,
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self getData];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 20)];
    headView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    return  headView;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BuZhouViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BuZhouViewCell" forIndexPath:indexPath];
    BuZhouModel *model = self.dataArray[indexPath.row];
    cell.numLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row +1];
    cell.typeLabel.text = model.title;
    
    cell.nameLabel.text = [NSString stringWithFormat:@"姓名:%@",model.real_name];
    cell.bumenLabel.text = [NSString stringWithFormat:@"部门:%@",model.section_name] ;
    cell.timeLabel.text = model.create_time;
    //[NSString stringWithFormat:@"时间:%@",[self ConvertStrToTime:model.create_time]]  ;
    cell.statusLabel.text = model.status;
    if ([model.title isEqualToString:@"当前步骤"]) {
        
        if ([model.real_name isEqualToString:@"已完成"]) {
            cell.leftLabel.hidden = YES;
            cell.typeLabel.text = model.real_name;
            cell.nameLabel.hidden = YES;
            cell.bumenLabel.hidden = YES;
            cell.timeLabel.hidden = YES;
        }else{
            cell.numLabel.backgroundColor = [UIColor redColor];
            cell.leftLabel.hidden = YES;
            cell.backImageView.image = [UIImage imageNamed:@"ico_bz_wt"];
            cell.timeLabel.hidden = YES;
            cell.typeLabel.textColor = [UIColor whiteColor];
            cell.nameLabel.textColor = [UIColor whiteColor];
            cell.bumenLabel.textColor = [UIColor whiteColor];
            cell.statusLabel.text = @"待处理";
            cell.statusLabel.textColor = [UIColor orangeColor];
            
        }
        
    }
    
    
    
    return cell;
}

//时间戳变为格式时间
- (NSString *)ConvertStrToTime:(NSString *)timeStr{
    
    long long time=[timeStr longLongValue];
    //    如果服务器返回的是13位字符串，需要除以1000，否则显示不正确(13位其实代表的是毫秒，需要除以1000)
    //    long long time=[timeStr longLongValue] / 1000;
    
    NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:time];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString*timeString=[formatter stringFromDate:date];
    
    return timeString;
    
}

-(void)getData{
    [[ApiManager ShardInstance]appealFlowChartId:self.appealID resultBlock:^(NSDictionary *data, NSError *error) {
        NSArray *array = [BuZhouModel mj_objectArrayWithKeyValuesArray:data[@"rs"][@"flow"]];
        
        [self.dataArray addObjectsFromArray:array];
        [self.tableView reloadData];
        
    }];
    
}


/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
